﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using BLL;

namespace Web.frontStage
{
    public partial class findlostpwd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        static private string GetConnectionString()
        {
            // To avoid storing the connection string in your code, 
            // you can retrieve it from a configuration file.
            return "Data Source=WEIWANG-PC\\SQLEXPRESS;Initial Catalog=iMovie;Integrated Security=True";
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string userName = username.Text.Trim();
            string safeAns = secretAnswner.Text.Trim();

            string MyConn = GetConnectionString();
            string sqlString = " select * from UserDetail_Tab where userDetail_name = ";
            sqlString += "'" + userName + "'";
            sqlString += " AND userDetail_safeAns = ";
            sqlString += "'" + safeAns + "'";


            SqlConnection MyConnection = new SqlConnection(MyConn);//定义一个数据连接实例
            SqlCommand MyCommand = new SqlCommand(sqlString, MyConnection); //定义一个数据库操作指令
            SqlDataAdapter SelectAdapter = new SqlDataAdapter();//定义一个数据适配器
            SelectAdapter.SelectCommand = MyCommand;//定义数据适配器的操作指令
            DataSet MyDataSet = new DataSet();//定义一个数据集
            MyConnection.Open();//打开数据库连接
            SelectAdapter.SelectCommand.ExecuteNonQuery();//执行数据库查询指令
            MyConnection.Close();//关闭数据库
            SelectAdapter.Fill(MyDataSet);//填充数据集
        
            string password = MyDataSet.Tables[0].Rows[0]["UserDetail_pwd"].ToString();
            string email = MyDataSet.Tables[0].Rows[0]["UserDetail_email"].ToString();

        
            SendMail mailsender = new SendMail();
            mailsender.sendMail(password,email);

            Response.Write("<script>alert('邮件发送成功');</script>");
            Response.Redirect("/frontStage/index.aspx");

         

        }
    }
}